home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
graphic
/
vansi.zip
/
NANSI_F.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-11-22
|
25KB
|
652 lines
page 66, 132
;----- nansi_f.asm ---------------------------------------------
; The ANSI control subroutines.
; (C) 1986 Daniel Kegel, Pasadena, CA
; May be distributed for educational and personal use only
; Each routine is called with the following register usage:
; AX = max(1, value of first parameter)
; Z flag is set if first parameter is zero.
; CX = number of paramters
; SI = offset of second parameter from CS
; DS = CS
; ES:DI points to the current location on the memory-mapped screen.
; DX is number of characters remaining on the current screen line.
; The control routine is free to trash AX, BX, CX, SI, and DS.
; It must preserve ES, and can alter DX and DI if it wants to move the
; cursor.
;
; Revisions:
; 19 Aug 85: Fixed horrible bug in insert/delete line.
; 26 Aug 85: Fixed simple limit-to-one-too-few-lines bug in ins/del line;
; anyway, it inserts 24 lines when on line 2 now. Whether it's fixed...
; 4 Sept 85: Fixed bug created on 26 Aug 85; when limiting ins/del line
; count, we are clearing, not scrolling; fixed BIOS call to reflect this.
; 30 Jan 86: Added EGA cursor patch
; 31 Jan 86: Disabled insert/delete char in graphics modes
; Implemented keyboard redefinition reset
; 1 Feb 86: added video_mode and max_x test after mode set
;----------------------------------------------------------------
include nansi_d.asm
; To nansi_p.asm
public ansi_fn_table
; From nansi.asm
extrn port_6845:word
extrn cur_coords:word, saved_coords:word
extrn cur_x:byte, max_x:byte
extrn cur_y:byte, max_y:byte
extrn cur_attrib:byte, wrap_flag:byte
extrn xy_to_regs:near
extrn get_blank_attrib:near
extrn xlate_tab_ptr:word
extrn cpr_esc:byte, cprseq:word
extrn video_mode:byte
extrn lookup:near
extrn in_g_mode:near
; from nansi_p.asm
extrn param_buffer:word ; used in keyboard programming
extrn param_end:word
extrn redef_end:word
keybuf struc ; used in making cpr sequence
len dw ?
adr dw ?
keybuf ends
ABS40 segment at 40h
org 1ah
buffer_head dw ? ; Used in 'flush input buffer' dos call.
buffer_tail dw ?
org 49h
crt_mode db ?
crt_cols dw ?
crt_len dw ?
crt_start dw ?
cursor_posn dw 8 dup (?)
cursor_mode dw ?
active_page db ?
addr_6845 dw ?
crt_mode_set db ?
crt_palette db ?
org 84h
crt_max_y db ? ; CJD 11/19/89 - EGA/VGA only
ABS40 ends
code segment byte public 'CODE'
assume cs:code, ds:code
;----- byteout ---------------------------------------------------
; Converts al to a decimal ASCII string (in 0..99),
; stores it at ES:DI++. Returns DI pointing at byte after last digit.
; Destroys DL.
byteout proc near
aam
add ax, 3030h
xchg ah, al
stosb
xchg ah, al
stosb
ret
byteout endp
;----- ansi_fn_table -----------------------------------
; Table of offsets of terminal control subroutines in order of
; the character that invokes them, @..Z, a..z. Exactly 53 entries.
; All the subroutines are defined below in this module.
ansi_fn_table label word
dw ic, cup, cdn, cfw, cbk ; @, A, B, C, D
dw nul, nul, nul, hvp, nul ; E, F, G, H, I
dw eid, eil, il, d_l, nul ; J, K, L, M, N
dw nul, dc, nul, nul, nul ; O, P, Q, R, S
dw nul, nul, nul, nul, nul ; T, U, V, W, X
dw nul, nul ; Y, Z
dw nul, nul, nul, nul, nul ; a, b, c, d, e
dw hvp, nul, sm, nul, nul ; f, g, h, i, j
dw nul, rm, sgr, dsr, nul ; k, l, m, n, o
dw key, nul, nul, scp, nul ; p, q, r, s, t
dw rcp, nul, nul, nul, xoc ; u, v, w, x, y
dw nul ; z
ansi_functions proc near ; set return type to NEAR
;----- nul ---------------------------------------------
; No-action ansi sequence; called when unknown command given.
nul: ret
;----- Cursor Motion -----------------------------------------------
;-- cursor to y,x
hvp: or al, al ; First parameter is desired Y coordinate.
jz hvp_yok
dec ax ; Convert to zero-based coordinates.
hvp_yok:mov cur_y, al
; Get second parameter, if it is there, and set X with it.
xor ax, ax
cmp cx, 2 ; was there a second parameter?
jb hvp_xok
lodsb ; yes.
or al, al
jz hvp_xok
dec ax ; convert to zero-based coordinates.
hvp_xok:mov cur_x, al
; Clip to maximum coordinates.
hvp_set:
mov ax, cur_coords ; al = x, ah = y
cmp al, max_x
jbe hvp_sxok
mov al, max_x
mov cur_x, al
hvp_sxok:
cmp ah, max_y
jbe hvp_syok
mov al, max_y
mov cur_y, al
hvp_syok:
; Set values of DX and DI accordingly.
call xy_to_regs
ret
;-- cursor forward --
cfw: add cur_x, al
jmp hvp_set
;-- cursor back -----
cbk: sub cur_x, al
jae cbk_ok
mov cur_x, 0
cbk_ok: jmp hvp_set
;-- cursor down -----
cdn: add cur_y, al
jmp hvp_set
;-- cursor up -------
cup: sub cur_y, al
jae cup_ok
mov cur_y, 0
cup_ok: jmp hvp_set
;-- save cursor position --------------------------------------
scp: mov ax, cur_coords
mov saved_coords, ax
ret
;-- restore cursor position -----------------------------------
rcp: mov ax, saved_coords
mov cur_coords, ax
jmp hvp_set ; Clip in case we have switched video modes.
;-- set graphics rendition ------------------------------------
; Modifies the color in which new characters are written.
sgr: dec si ; get back pointer to first parameter
or cx, cx ; Did he give any parameters?
jnz sgr_loop
mov byte ptr [si], 0 ; no parameters, so fake
inc cx ; one with the default value.
; For each parameter
sgr_loop:
lodsb ; al = next parameter
; Search color table
push cx
mov cx, colors
mov bx, offset color_table-3
sgr_search:
add bx, 3
cmp al, byte ptr [bx]
loopnz sgr_search ; until match found or done
jnz sgr_loopx
; If parameter named a known color, set the current
; color variable.
mov ax, [bx+1]
and cur_attrib, al
or cur_attrib, ah
sgr_loopx:
pop cx
loop sgr_loop ; until no more parameters.
ret
;-- erase in line ----------------------------------------
; Uses BIOS to scroll away a one-line rectangle
eil: push dx
mov cx, cur_coords
mov dh, ch
jmp short scrollem
;-- erase in display -------------------------------------
; Uses BIOS to scroll away all of display
eid: cmp al, 2
jnz eid_ignore ; param must be two
if cls_homes_too
mov cur_coords, 0
call xy_to_re